import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/doctor_patrol/doctor_patrol_model.dart';
import 'package:ls_work/ui/select_old_page.dart';
class CreateDoctorPatrolViewModel extends BaseViewModel{
  CreateDoctorPatrolViewModel(super.context);

  SubmitDoctorPatrolData data = SubmitDoctorPatrolData(healthReport: SubmitDoctorPatrolHealth());

  String customerName = "";
  
  var model = DoctorPatrolModel();

  void chooseElder(){
    Go().push(SelectOldPage((old){
      Go().pop();
      data.customerElderId = old.id;
      customerName = old.name??"";
      notifyListeners();
    }));
  }

  var format = [yyyy,'-',mm,'-',dd,' ',HH,':',nn,':',ss];
  void chooseTime(){
    var current = data.finishTime?.toDate();
    DatePicker.showDateTimePicker(context,currentTime: current,onConfirm: (date){
      data.finishTime = date!.toDateStr(format);
      notifyListeners();
    });
  }
  
  
  Future<void> submitClick() async {
    if(data.customerElderId==null){
      showToast("请选择长者");
      return;
    }
    if(data.finishTime.isNullOrEmpty()){
      showToast('请选择时间');
      return;
    }

    showLoadingDialog(msg: '提交中...');
    try{
      await model.addPatrolInfo(data);
      hideDialog();
      showToast('提交成功');
      finish(data: true);
    }catch(e){
      hideDialog();
      showToast(e.toNetError());
    }
  }
  
}